package concurrent;

/**
 * @Description: TODO interrupt interrupted isInterrupted区别
 * @Author: wzj
 * @Date: 2020/11/25 11:44
 */
public class InterruptDemo {
    /**
     * interrupt 中断一个线程。实例方法
     * interrupted 中断当前线程，并清除中断状态：是当前线程Thread.currentThread()，而不是调用这个方法的线程。静态方法
     * isInterrupted 判断此线程是否中断。实例方法
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("~~~~~此线程~~~~~");
        Thread thread=new InterruptThread();//此线程
        thread.start();
        thread.interrupt();
        System.out.println(thread.isInterrupted());
        System.out.println(thread.interrupted());//不起作用 因为不是当前线程
        System.out.println(thread.interrupted());

        System.out.println("~~~~~当前线程~~~~~");
        Thread thread1=Thread.currentThread();//当前线程
        thread1.interrupt();
        System.out.println(thread1.isInterrupted());//true
        System.out.println(thread1.interrupted());//true
        System.out.println(thread1.isInterrupted());//false 因为上面一行 清除中断状态了 即为非中断
        System.out.println(thread1.interrupted());

    }
}

class InterruptThread extends Thread{

}
